package org.fyp.synchrona.blog.service;

import org.apache.log4j.Logger;
import org.fyp.synchrona.blog.service.util.OldData;





public class OldDataProcessor {
	
	OldData OldDataObj;
	
	static final Logger logger = Logger.getLogger(OldDataProcessor.class);
	
	public OldDataProcessor(OldData Od){
		OldDataObj = Od;
	}
	
	public void retriveOldParameters(String editPage){
		
		requiredParameters(editPage);
		getOldEmailAddress(editPage);
		getwidget_displayname(editPage);
		getFirstName(editPage);
		getLastName(editPage);
		getPhotoURL(editPage);
		getPhotoHeight(editPage);
		getPhotoWidth(editPage);
		getImageFileName(editPage);
		getAudioclipurl(editPage);
		getGender(editPage);
		getBirthMonth(editPage);
		getBirthDay(editPage);
		getBirthYear(editPage);
		getShowAstrologicalSigns(editPage);
		getURL(editPage);
		getWishlisturl(editPage);
		getImusername(editPage);
		getimnetwork(editPage);
		getwidget_city(editPage);
		getwidget_state(editPage);
		getwidget_country(editPage);
		getind(editPage);
		getoccupation(editPage);
		getinterests(editPage);
		getwidget_aboutme(editPage);
		getmovies(editPage);
		getmusic(editPage);
		getbooks(editPage);
		getwackyQuestion(editPage);
		getwackyAnswer(editPage);
		getSubmission(editPage);
	}
	
	private void requiredParameters(String editPage) {
		String[] array = editPage.split("securityToken\" type=\"hidden\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setSecurityToken(array[0]);
		array = editPage.split("security_token\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setSecurity_Token(array[0]);
		array = editPage.split("id=\"USI_");
		array = array[1].split("_asynchronous");
		String USI = array[0];
		OldDataObj.setUSIRadio("USI_" + USI + "_imgSrcRadio");
		OldDataObj.setUSIError("USI_" + USI + "_imgUrlTextError");
	}
////////////////////
	private void getOldEmailAddress(String editPage) {
		String[] array = editPage.split("email\" value=\"");
		array = array[1].split("\">");
		int index = array[0].indexOf("\"");
		String oldmail = array[0].substring(0,index);
		OldDataObj.setEmail(oldmail);
	}
	private void getwidget_displayname(String editPage){
		String[] array = editPage.split("widget.displayname\" id=\"widget.displayname\" type=\"text\" class=\"text\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setWidget_displayname(array[0]);
	}
	private void getFirstName(String editPage){
		String[] array = editPage.split("text\" name=\"firstname\" value=\"");
		array = array[1].split("\" id=");
		OldDataObj.setFirstName(array[0]);
	}
	private void getLastName(String editPage){
		String[] array = editPage.split("text\" name=\"lastname\" value=\"");
		array = array[1].split("\" id=");
		OldDataObj.setLastName(array[0]);
	}
	private void getPhotoURL(String editPage){
		String[] array = editPage.split("photourl\" name=\"photourl\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setPhotourl(array[0]);
	}
	private void getPhotoWidth(String editPage){
		String[] array = editPage.split("photowidth\" name=\"photowidth\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setPhotowidth(array[0]);
	}
	private void getPhotoHeight(String editPage){
		String[] array = editPage.split("photoheight\" name=\"photoheight\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setPhotoheight(array[0]);
	}
	private void getImageFileName(String editPage) {
		// TODO Auto-generated method stub
		OldDataObj.setImageFileName("");
	}
	private void getAudioclipurl(String editPage) {
		String[] array = editPage.split("text\" name=\"audioclipurl\" value=\"");
		array = array[1].split("\" style=");
		OldDataObj.setAudioclipurl(array[0]);
	}
	private void getGender(String editPage) {
		String[] array = editPage.split("input type=\"radio\" name=\"gender\" checked value=\"");
		array = array[1].split("\" id=");
		OldDataObj.setGender(array[0]);
	}
	private void getBirthMonth(String editPage) {
		String[] array = editPage.split("text\" name=\"birthmonth\" value=\"");
		array = array[1].split("\" size=");
		OldDataObj.setBirthmonth(array[0]);
		
	}
	private void getBirthYear(String editPage) {
		//
		String[] array = editPage.split("text\" name=\"birthyear\" value=\"");
		array = array[1].split("\" size=");
		OldDataObj.setBirthyear(array[0]);
	}
	private void getBirthDay(String editPage) {
		//text" name="birthday" value="
		String[] array = editPage.split("text\" name=\"birthday\" value=\"");
		array = array[1].split("\" size=");
		OldDataObj.setBirthday(array[0]);
	}
	private void getShowAstrologicalSigns(String editPage) {
		String[] array = editPage.split("checkbox\" name=\"showAstrologicalSigns\" checked value=\"");
		array = array[1].split("\" id=\"showAstrologicalSigns");
		logger.info("[BLOGGER] oldData ShowAstrologicalSigns ::"+array[0]);
		OldDataObj.setShowAstrologicalSigns(array[0]);
	}
	private void getURL(String editPage) {
		String[] array = editPage.split("text\" name=\"url\" value=\"");
		array = array[1].split("\" id=\"url");
		logger.info("[BLOGGER] oldData URL ::"+array[0]);
		OldDataObj.setUrl(array[0]);
	}	
	private void getWishlisturl(String editPage) {
		String[] array = editPage.split("text\" name=\"wishlisturl\" value=\"");
		array = array[1].split("\" id=\"wishlisturl");
		logger.info("[BLOGGER] oldData Wishlisturl ::"+array[0]);
		OldDataObj.setUrl(array[0]);
	}
	private void getImusername(String editPage) {
		String[] array = editPage.split("text\" name=\"imusername\" value=\"");
		array = array[1].split("\" class");
		OldDataObj.setImusername(array[0]);
	}
	private void getimnetwork(String editPage) {
		String[] array = editPage.split("imnetwork\"><option value=\"");
		array = array[1].split("\">None</option>");
		OldDataObj.setImnetwork(array[0]);
	}
	private void getwidget_city(String editPage) {
		String[] array = editPage.split("text\" name=\"widget.city\" value=\"");
		array = array[1].split("\" id=\"widget.city\"");
		OldDataObj.setWidget_city(array[0]);
	}
	private void getwidget_state(String editPage) {
		String[] array = editPage.split("text\" name=\"widget.state\" value=\"");
		array = array[1].split("\" id=\"widget.state\"");
		OldDataObj.setWidget_state(array[0]);
		
	}
	private void getwidget_country(String editPage) {
		//System.out.println(editPage);
		String[] array = editPage.split("widget.country\" tabindex=\"0\" id=\"widget.country\"><option value=\"");
		array = array[1].split("\"");
		//System.out.println(array[0]);
		OldDataObj.setWidget_country(array[0]);
	}
	private void getind(String editPage) {
		String[] array = editPage.split("select name=\"ind\" tabindex=\"0\" id=\"ind\"><option value=\"");
		array = array[1].split("\">");
		OldDataObj.setInd(array[0]);
		
	}
	private void getoccupation(String editPage) {
		String[] array = editPage.split("text\" name=\"occupation\" value=\"");
		array = array[1].split("\" class=");
		OldDataObj.setOccupation(array[0]);
	}
	private void getinterests(String editPage) {
		String[] array = editPage.split("interests\" rows=\"4\" cols=\"30\" class=\"text-custom\" id=\"interests\">");
		array = array[1].split("</textarea>");
		OldDataObj.setInterests(array[0]);
		
	}
	private void getwidget_aboutme(String editPage) {
		String[] array = editPage.split("widget.aboutme\" rows=\"4\" cols=\"30\" class=\"text-custom\" id=\"widget.aboutme\">");
		array = array[1].split("</textarea>");
		OldDataObj.setWidget_aboutme(array[0]);
		
	}
	private void getmovies(String editPage) {
		String[] array = editPage.split("textarea name=\"movies\" rows=\"4\" cols=\"30\" class=\"text-custom\" id=\"movies\">");
		array = array[1].split("</textarea>");
		OldDataObj.setMovies(array[0]);
	}
	private void getmusic(String editPage) {
		String[] array = editPage.split("textarea name=\"music\" rows=\"4\" cols=\"30\" class=\"text-custom\" id=\"music\">");
		array = array[1].split("</textarea>");
		OldDataObj.setMusic(array[0]);
		
	}
	private void getbooks(String editPage) {
		String[] array = editPage.split("textarea name=\"books\" rows=\"4\" cols=\"30\" class=\"text-custom\" id=\"books\">");
		array = array[1].split("</textarea>");
		OldDataObj.setBooks(array[0]);
		
	}
	private void getwackyQuestion(String editPage) {
		String[] array = editPage.split("hidden\" name=\"wackyQuestion\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setWackyQuestion(array[0]);
		
	}
	private void getwackyAnswer(String editPage) {
		String[] array = editPage.split("text\" name=\"imusername\" value=\"");
		array = array[1].split("\" class");
		OldDataObj.setWackyAnswer(array[0]);
		
	}
	private void getSubmission(String editPage){
		String[] array = editPage.split("submitButton\" tabindex=\"0\" value=\"");
		array = array[1].split("\">");
		OldDataObj.setSubmitButton(array[0]);
	}
}
